package com.itlong.cloud.sdk.resource;

import com.itlong.cloud.POJO.DTO.sdk.*;
import com.itlong.cloud.POJO.PO.BuildInfoPO;
import com.itlong.cloud.POJO.PO.ProjectPO;
import com.itlong.cloud.POJO.PO.RoomInfoPO;
import com.itlong.cloud.POJO.PO.UnitInfoPO;
import com.itlong.cloud.POJO.VO.sdk.CloudTalkSDKServerGetBuildVO;
import com.itlong.cloud.POJO.VO.sdk.CloudTalkSDKServerGetUnitVO;
import com.itlong.cloud.POJO.VO.sdk.SDKServerProjectInfoListPageVO;
import com.itlong.cloud.project.sdk.ICloudTalkSDKServerProjectServiceClient;
import com.itlong.cloud.sdk.service.ICloudTalkSDKServerProjectService;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      云对讲SDK项目服务层暴露接口实现类
 * </desc>
 *
 * @createDate 2018/05/17
 */
@RestController
public class CloudTalkSDKServerProjectServiceResource implements ICloudTalkSDKServerProjectServiceClient {

    @Autowired
    private ICloudTalkSDKServerProjectService iCloudTalkSDKServerProjectService;

    /**
     * <desc>
     *      根据参数字段查询build_info信息
     * <desc/>
     *
     * @param param 查询参数集
     * @return List<BuildInfoPO> 返回对象集
     * @author wangzhi
     * @createDate 2018/05/17
     */
    @Override
    @PostMapping(path = "cloudTalkSDK/build/getBuildByParam")
    public List<BuildInfoPO> getBuildByParam(@RequestBody Map<String, Object> param) {
        return iCloudTalkSDKServerProjectService.getBuildByParam(param);
    }

    /**
     * <desc>
     *      更新项目楼栋信息
     * </desc>
     *
     * @param buildUpdates 待更新的PO对象集
     * @return 更新的数量
     * @author wangzhi
     * @createDate 2018/05/17
     */
    @Override
    @PostMapping(path = "cloudTalkSDK/build/updateBuild")
    public Integer updateBuild(@RequestBody List<BuildInfoPO> buildUpdates) {
        return iCloudTalkSDKServerProjectService.updateBuild(buildUpdates);
    }

    /**
     * <desc>
     *      保存项目楼栋信息
     * </desc>
     *
     * @param buildSaves 待保存的PO对象集
     * @return 保存的数量
     * @author wangzhi
     * @createDate 2018/05/17
     */
    @Override
    @PostMapping(path = "cloudTalkSDK/build/saveBuild")
    public Integer saveBuild(@RequestBody List<BuildInfoPO> buildSaves) {
        return iCloudTalkSDKServerProjectService.saveBuild(buildSaves);
    }

    /**
     * <desc>
     *      根据参数字段查询unit_info信息
     * <desc/>
     *
     * @param param 查询参数集
     * @return List<UnitInfoPO> 返回对象集
     * @author wangzhi
     * @createDate 2018/05/17
     */
    @Override
    @PostMapping(path = "cloudTalkSDK/build/getUnitByParam")
    public List<UnitInfoPO> getUnitByParam(@RequestBody Map<String, Object> param) {
        return iCloudTalkSDKServerProjectService.getUnitByParam(param);
    }

    /**
     * <desc>
     *      更新项目单元信息
     * </desc>
     *
     * @param unitUpdates 待更新的PO对象集
     * @return 更新的数量
     * @author wangzhi
     * @createDate 2018/05/17
     */
    @Override
    @PostMapping(path = "cloudTalkSDK/build/updateUnit")
    public Integer updateUnit(@RequestBody List<UnitInfoPO> unitUpdates) {
        return iCloudTalkSDKServerProjectService.updateUnit(unitUpdates);
    }

    /**
     * <desc>
     *      保存项目单元信息
     * </desc>
     *
     * @param unitSaves 待更新的PO对象集
     * @return 更新的数量
     * @author wangzhi
     * @createDate 2018/05/17
     */
    @Override
    @PostMapping(path = "cloudTalkSDK/build/saveUnit")
    public Integer saveUnit(@RequestBody List<UnitInfoPO> unitSaves) {
        return iCloudTalkSDKServerProjectService.saveUnit(unitSaves);
    }

    /**
     * <desc>
     *      云对讲SDK批量添加用户房间信息
     * <desc/>
     * @param saveAppUserDTOs     用户房间信息
     * @return
     * @author JuGuang.S
     * @createDate 2018/05/17
     */
    @PostMapping(path = "/cloudTalkSdk/server/addUserRoomInfo")
    public Map<String,Object> addUserRoomInfo(@RequestBody List<SDKSaveAppUserDTO> saveAppUserDTOs){
        return iCloudTalkSDKServerProjectService.addUserRoomInfo(saveAppUserDTOs);
    }

    /**
     * <desc>
     *      根据参数字段查询room_info信息
     * </desc>
     *
     * @param param 查询参数集
     * @return List<RoomInfoPO>返回对象集
     * @author wangzhi
     * @createDate 2018/05/18
     */
    @Override
    @PostMapping(path = "/cloudTalkSdk/server/getRoomByParam")
    public List<RoomInfoPO> getRoomByParam(@RequestBody Map<String, Object> param) {
        return iCloudTalkSDKServerProjectService.getRoomByParam(param);
    }

    /**
     * <desc>
     *      更新项目房间信息
     * </desc>
     *
     * @param roomUpdates 待更新的PO对象集
     * @return 更新的数量
     * @author wangzhi
     * @createDate 2018/05/18
     */
    @Override
    @PostMapping(path = "/cloudTalkSdk/server/updateRoom")
    public Integer updateRoom(@RequestBody List<RoomInfoPO> roomUpdates) {
        return iCloudTalkSDKServerProjectService.updateRoom(roomUpdates);
    }

    /**
     * <desc>
     *      保存项目房间信息
     * </desc>
     *
     * @param roomSaves 待保存的PO对象集
     * @return 更新的数量
     * @author wangzhi
     * @createDate 2018/05/18
     */
    @Override
    @PostMapping(path = "/cloudTalkSdk/server/saveRoom")
    public Integer saveRoom(@RequestBody List<RoomInfoPO> roomSaves) {
        return iCloudTalkSDKServerProjectService.saveRoom(roomSaves);
    }

    /**
     * <desc>
     *      云对讲SDK查看该项目下是否存在指定用户
     * <desc/>
     * @param projectId     项目编号
     * @param userId     用户Id
     * @return
     * @author JuGuang.S
     * @createDate 2018/05/21
     */
    @Override
    @PostMapping(path = "/cloudTalkSdk/server/userIsExist")
    public Integer userIsExist(@RequestParam(name = "projectId") String projectId, @RequestParam(name = "userId") String userId) {
        return iCloudTalkSDKServerProjectService.userIsExist(projectId,userId);
    }

    /**
     * <desc>
     *      云对讲SDK修改项目下指定用户的禁用启用状态
     * <desc/>
     * @param param 项目编号、用户ID、所要改变的状态
     * @return
     * @author JuGuang.S
     * @createDate 2018/05/21
     */
    @Override
    @PostMapping(path = "/cloudTalkSdk/server/modifyUserStatus")
    public void modifyUserStatus(@RequestBody Map<String, Object> param) {
        iCloudTalkSDKServerProjectService.modifyUserStatus(param);
    }

    /**
     * <desc>
     *      根据projectId,buildNum,unitNum和roomNum查询房间信息
     * <desc/>
     * @param       params      待查询的参数集
     * @return      符合的房间对象集
     * @author JuGuang.S
     * @createDate 2018/05/21
     */
    @PostMapping(path = "/cloudTalkSdk/server/getRoomByPiBnUnRn")
    @Override
    public List<RoomInfoPO> getRoomByPiBnUnRn(@RequestBody Map<String, Object> params) {
        return iCloudTalkSDKServerProjectService.getRoomByPiBnUnRn(params);
    }

    /**
     * <desc>
     *      根据projectId,buildNum,unitNum和roomNum查询该房间下是否已有业主
     * <desc/>
     * @param       params      待查询的参数集
     * @return      符合的房间对象集
     * @author JuGuang.S
     * @createDate 2018/12/6
     */
    @PostMapping(path = "/cloudTalkSdk/server/getIsOwnerUser")
    @Override
    public Integer getIsOwnerUser(@RequestBody Map<String, Object> params) {
        return iCloudTalkSDKServerProjectService.getIsOwnerUser(params);
    }

    /**
     * <desc>
     *      根据项目ID和pubKey查询单个项目
     * <desc/>
     * @param  desProjectId  待查询项目ID
     * @param  pubKey  项目密钥
     * @return  ProjectPO  返回对象
     * @author JuGuang.S
     * @createDate 2018/05/11
     */
    @PostMapping(path = "/cloudTalkSdk/server/getByProjectIdAndPubKey")
    @Override
    public ProjectPO getByProjectIdAndPubKey(@RequestParam("desProjectId") String desProjectId, @RequestParam("pubKey") String pubKey) {
        return iCloudTalkSDKServerProjectService.getByProjectIdAndPubKey(desProjectId,pubKey);
    }

    /**
     * <desc>
     *      根据项目编号查询sip的ip和port
     * <desc/>
     * @param  projectId  查询项目ID
     * @return  Map<String,String>  返回sip的ip和port
     * @author JuGuang.S
     * @createDate 2018/05/14
     */
    @PostMapping(path = "sdkServer/project/getSipInfoByProjectId")
    @Override
    public Map<String,Object> getSipInfoByProjectId(@RequestParam("projectId") String projectId) {
        return iCloudTalkSDKServerProjectService.getSipInfoByProjectId(projectId);
    }

    /**
     * <desc>
     *      获取项目的楼栋信息列表
     * </desc>
     *
     * @param cloudTalkSDKServerGetBuildListDTO 查询参数
     * @return 楼栋信息列表
     * @author wangzhi
     * @createDate 2018/05/23
     */
    @Override
    @PostMapping(path = "/cloudTalkSDK/server/getBuildList")
    public CloudTalkSDKServerGetBuildVO getBuildList(@RequestBody CloudTalkSDKServerGetBuildListDTO cloudTalkSDKServerGetBuildListDTO) throws Exception{
        return iCloudTalkSDKServerProjectService.getBuildList(cloudTalkSDKServerGetBuildListDTO);
    }

    /**
     * <desc>
     *      获取项目楼栋的单元信息列表
     * </desc>
     *
     * @param cloudTalkSDKServerGetUnitListDTO 查询参数
     * @return 楼栋信息列表
     * @author wangzhi
     * @createDate 2018/05/23
     */
    @Override
    @PostMapping(path = "/cloudTalkSDK/server/getUnitList")
    public CloudTalkSDKServerGetUnitVO getUnitList(@RequestBody CloudTalkSDKServerGetUnitListDTO cloudTalkSDKServerGetUnitListDTO) throws Exception {
        return iCloudTalkSDKServerProjectService.getUnitList(cloudTalkSDKServerGetUnitListDTO);
    }

    /**
     * <desc>
     *      根据appId查询项目列表
     * <desc/>
     * @param       pageDTO      用户名称
     * @return      项目集
     * @author Qiang.S
     * @createDate 2018/05/23
     */
    @PostMapping(path = "/cloudTalkSdk/server/getProjectList")
    @Override
    public Page<SDKServerProjectInfoListPageVO> getProjectList(@RequestBody CloudTalkSDKServerGetProjectInfoPageDTO pageDTO) throws Exception {
        return iCloudTalkSDKServerProjectService.getProjectList(pageDTO);
    }

    /**
     * <desc>
     *      上传苹果推送证书
     * </desc>
     *
     * @return 受影响的行数
     * @author wangzhi
     * @createDate 2018/11/22
     */
    @Override
    @PostMapping(path = "/cloudTalkSdk/server/uploadApplePush")
    public Integer uploadApplePush(@RequestBody CloudTalkSDKServerUploadApplePushDTO cloudTalkSDKServerUploadApplePushDTO) throws Exception {
        return iCloudTalkSDKServerProjectService.uploadApplePush(cloudTalkSDKServerUploadApplePushDTO);
    }

    /**
     * <desc>
     *      根据项目编号和角色为开发者账号查询当前项目绑定的灵云快智的应用账号信息
     * <desc/>
     * @param  projectId  查询项目ID
     * @param  roleId  开发者账号
     * @return
     * @author JuGuang.S
     * @createDate 2018/12/21
     */
    @Override
    @PostMapping(path = "sdkServer/project/getBingLykzAppId")
    public String getBingLykzAppId(@RequestParam("projectId") String projectId,@RequestParam("roleId") String roleId,@RequestParam("appId") String appId){
        return iCloudTalkSDKServerProjectService.getBingLykzAppId(projectId,roleId,appId);
    }

}
